
# 列车上有一排 n 个座位，乘客按顺序上车，每路过一个合法座位时，落座概率是 p，合法座位是指：目标座位和目标座位前面都没人坐
# 求座位坐满时乘客数量的期望 m 对 n 的比值

import numpy as np


n = 10_000
p = 0.9

temp = np.ones(n + 2, dtype=bool)
temp[0] = False
temp[-1] = False
rands = np.random.exponential(1/p, n * 100).astype(int) + 1

for i, s in enumerate(rands):
    if not temp.any():
        break
    for j, t in enumerate(temp[:-1]):
        s -= t
        if s == 0:
            break
    temp[[j-1, j, j+1]] = False

print(i)
